<?php
/**********************************************************************
    Copyright (C) FrontAccounting, LLC.
	Released under the terms of the GNU General Public License, GPL, 
	as published by the Free Software Foundation, either version 3 
	of the License, or (at your option) any later version.
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
    See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/
$page_security = $_POST['PARAM_0'] == $_POST['PARAM_1'] ?
	'SA_SALESTRANSVIEW' : 'SA_SALESBULKREP';
// ----------------------------------------------------------------
// $ Revision:	2.0 $
// Creator:	Joe Hunt
// date_:	2005-05-19
// Title:	Print Sales Orders
// ----------------------------------------------------------------
$path_to_root="..";

/*include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/data_checks.inc");
include_once($path_to_root . "/sales/includes/sales_db.inc");
include_once($path_to_root . "/taxes/tax_calc.inc");
*/
include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/includes/data_checks.inc");
include_once($path_to_root . "/sales/includes/sales_db.inc");
include_once($path_to_root . "/taxes/tax_calc.inc");
include_once($path_to_root . "/reporting/includes/reporting.inc");
include($path_to_root . "/pittycash/includes/db/pittycash_db.inc");


print_sales_orders();

$print_as_quote = 0;

function print_sales_orders()
{
	global $path_to_root, $print_as_quote;

	include_once($path_to_root . "/reporting/includes/pdf_report.inc");

	$from = $_POST['PARAM_0'];
	$to = $_POST['PARAM_1'];
	$currency = $_POST['PARAM_2'];
	$email = $_POST['PARAM_3'];
	$print_as_quote = $_POST['PARAM_4'];
	$comments = $_POST['PARAM_5'];

	if ($from == null)
		$from = 0;
	if ($to == null)
		$to = 0;
	$dec = user_price_dec();

	$cols = array(4, 60, 150, 300,340, 400);
    // $cols = array(4, 100, 600);

	// $headers in doctext.inc
	$aligns = array('left',	'left','left','center','right');
     
	$params = array('comments' => $comments);

	$cur = get_company_Pref('curr_default');

	if ($email == 0)
	{
		if ($print_as_quote == 0)
		$rep = new FrontReport(_("SALES ORDER"), "SalesOrderBulk", user_pagesize());			
		else
			$rep = new FrontReport(_("QUOTE"), "QuoteBulk", user_pagesize());
		$rep->SetHeaderType('Header9');
		$rep->currency = $cur;
		$rep->Font();
		$rep->Info($params, $cols, null, $aligns);
		
	}

	for ($i = $from; $i <= $to; $i++)
	{
		$myrow = get_kas_bon($i, ST_KASBON);
	
		if ($email == 1)
		{
			
			$rep = new FrontReport("", "", user_pagesize());
			$rep->SetHeaderType('Header9');
			$rep->currency = $cur;
			$rep->Font();
			if ($print_as_quote == 1)
			{
				$rep->title = _('QUOTE');
				$rep->filename = "Quote" . $i . ".pdf";
			}
			else
			{
				$rep->title = _("SALES ORDER");
				$rep->filename = "SalesOrder" . $i . ".pdf";
			}
			$rep->Info($params, $cols, null, $aligns);
			
		}
		else
		$rep->title = ($print_as_quote==1 ? _("QUOTE") : _("SALES ORDER"));
		$rep->SetCommonData($myrow, null, $myrow, null, ST_KASBONPENYELESAIAN, null);
		$rep->NewPage();
        
		
		$result = get_kas_bon_details($i);
		$dec2 = 0;
	    $SubTotal = 0;
	    $kasawal=0;
		$x=0;
	    while ($myrow2=db_fetch($result))
		{	$x++;
			$rep->TextCol(0, 1,	$x, -2);
		    $rep->TextCol(1, 2,	$myrow2['no_note'], -2);
			$rep->TextCol(2, 3,	$myrow2['note'], -2);
			$rep->TextCol(3, 4,	Rp, -2);
			$rep->TextCol(4, 5,	price_decimal_format($myrow2["amount"],$dec2), -2);
			$rep->NewLine(1);
			if ($rep->row < $rep->bottomMargin + (15 * $rep->lineHeight))
				$rep->NewPage();
				
			$SubTotal += round2($myrow2["amount"],$dec);	
		}
		$kasawal=$myrow['amount'];
	//	$rep->row = $rep->bottomMargin + (15 * $rep->lineHeight);
		//$rep->TextCol(3, 6, _("Sub-total"), -2);
		//$rep->TextCol(6, 7,	$DisplaySubTot, -2);
		//$rep->NewLine();

		$rep->NewLine();
		$DisplayTotal = number_format2($SubTotal, $dec);
		$DisplaySisa  = number_format2($kasawal-$SubTotal, $dec);
		$rep->Font('bold');
		$rep->TextCol(0, 5, _("Total Penggunaan Kas Bon"), - 2);
		$rep->TextCol(5, 6,	$DisplayTotal, -2);
		$rep->NewLine();
        $rep->TextCol(0, 4, _("Kas Kembali"), - 2);
		$rep->TextCol(5, 6,	$DisplaySisa, -2);
	
			
	}
	if ($email == 0)
		$rep->End();
		
}

?>